package com.xml_.jsoup_;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        // 获取Document对象
        String path = "src\\com\\xml_\\student.xml";
        Document document = Jsoup.parse(new File(path), "utf-8");

        // 1、获取所有的student对象
        Elements elements = document.getElementsByTag("student");  // 返回的是以字符串形式的集合
        System.out.println(elements);

        // 2、获取属性名为number的标签对象们
        System.out.println("----------------------------------------");
        Elements elements1 = document.getElementsByAttribute("number");
        System.out.println(elements1);

        // 3、获取number属性值为a001的元素对象
        System.out.println("----------------------------------------");
        Elements elements2 = document.getElementsByAttributeValue("number", "a001");
        System.out.println(elements2);
    }
}

